<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends MX_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct()
	{
		parent::__construct();
        $this->display->set_theme('site');
	}
	
    public function index()
    {
    }
	public function view($id)
	{	 
		$this->load->library('display');
        $this->load->model('page_model');
        $this->load->model('content_model');
        $language = $this->config->item('site_default_language');
		//$this->display->template('main', array('user' => 'yugo'));
		
		// $this->display->json($json);
		
		// check page id
		if(ctype_digit($id) == FALSE) // NIET GOED IS VOOR CMS
		{
			return;
		}
		
		// check permission
		//permission('cms', 'pages');
        
		// get page
        $page = $this->page_model->get(array('page_id' => $id));
        
		// check page exists
		if( ! $page )
        {
            // 404
            return;
        }
		
        $data['page'] = $page;
		// check page permissions
		$data['content'] =  $this->content_model->get(array('page_id' => $id, 'language' => $language));
        $data['content'] = $data['content'][0];
		//print_r($data);
		// has comments?
			// yes: get comments for page
		//Array ( [page_id] => 13 [page_created] => 2012-10-25 09:01:20 [page_modified] => 2012-08-22 21:04:30 [layout] => frontpage [widgets] => 
		// [page_parent] => 0 [page_name] => News [order] => 0 [url] => News ) 
		// get widgets from page data
		
		// include widgets
		
		// Show page
		
        $this->twiggy->title()->append($page['page_name']);
		$page_layouts = $this->display->get_config('page_layouts');
        foreach($page_layouts as $layout)
        {
            if($layout['name'] == $page['layout'])
            {
                $this->display->template($layout['file'], $data);                
                break;
            }
        }	
		
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */